import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3

Item {
    width: 850
    height: 580

    signal qmlSN_sqlWriteFinish()
    onQmlSN_sqlWriteFinish: {
//        console.log("->page8 operater start")
        for(var i=0; i<p8_runModel.checkBoxArray_A.length; i++)
            if($sqlMcRecorder.qml_getBitBool("A套","调节器状态",p8_runModel.checkBoxArray_A[i].text)===true)
                p8_runModel.checkBoxArray_A[i].checked = true;
        else
                p8_runModel.checkBoxArray_A[i].checked = false;

        for(i=0; i<p8_runModel.checkBoxArray_B.length; i++)
            if($sqlMcRecorder.qml_getBitBool("B套","调节器状态",p8_runModel.checkBoxArray_B[i].text)===true)
                p8_runModel.checkBoxArray_B[i].checked = true;
            else
                p8_runModel.checkBoxArray_B[i].checked = false;

        if($sqlMcRecorder.qml_getBitBool("A套","调节器状态","PSS投入")===true)
            thirdPage_textStatuA.text = '已投入';
        else
            thirdPage_textStatuA.text = '已退出';
        if($sqlMcRecorder.qml_getBitBool("B套","调节器状态","PSS投入")===true)
            thirdPage_textStatuB.text = '已投入';
        else
            thirdPage_textStatuB.text = '已退出';

//        console.log("->page8 operater stop")
    }

    SwipeView{
        id:p8_swipeView
        orientation: Qt.Horizontal
        clip: true
        currentIndex: 0
        width: parent.width
        height: parent.height*0.8

        Item {
//            id: secondPage
            Page_08OperatorMonitor_RunModel {
                id: p8_runModel
                width: p8_swipeView.width
                height: p8_swipeView.height
            }
        }
        Item {
            id: thirdPage
            Item {
                id: element
                anchors.fill: parent

                ColumnLayout {
                    id: column
                    width: p8_swipeView.width
                    height: p8_swipeView.height

                    Row {
                        id: rowA
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                        Text {
                            id: thirdPage_textTipA
                            text: qsTr("A通道PSS状态:")
                            font.pointSize: 30
                            color: "#60FFFF"
                            anchors.verticalCenter: parent.verticalCenter
                            font.family: "Arial"
                            horizontalAlignment: Text.AlignRight
                            elide: Text.ElideLeft
                            wrapMode: Text.NoWrap
                        }
                        Text {
                            id: thirdPage_textStatuA
                            color: "#08bb73"
                            text: qsTr("已退出")
                            font.pointSize: 30
                            anchors.verticalCenter: parent.verticalCenter
                            styleColor: "#f0d8be"
                            font.family: "Arial"
                        }
                        EXC_Normal_BtnUncheckSecret_highStyle{
                            width: parent.parent.width/7
                            nameText: qsTr("投入")
                            onClicked: {
                                $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A套PSS投入\''))
                            }
                        }
                        EXC_Normal_BtnUncheckSecret_highStyle{
                            width: parent.parent.width/7
                            nameText: qsTr("退出")
                            onClicked: {
                                $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'A套PSS退出\''))
                            }
                        }
                    }

                    Row {
                        id: rowB
                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                        Text {
                            id: thirdPage_textTipB
                            text: qsTr("B通道PSS状态:")
                            color: "#60FFFF"
                            anchors.verticalCenter: parent.verticalCenter
                            font.family: "Arial"
                            font.pointSize: 30
                            horizontalAlignment: Text.AlignRight
                            elide: Text.ElideLeft
                            wrapMode: Text.NoWrap
                        }
                        Text {
                            id: thirdPage_textStatuB
                            color: "#08bb73"
                            text: qsTr("已退出")
                            anchors.verticalCenter: parent.verticalCenter
                            styleColor: "#f0d8be"
                            font.family: "Arial"
                            font.pointSize: 30
                        }
                        EXC_Normal_BtnUncheckSecret_highStyle{
                            width: parent.parent.width/7
                            nameText: qsTr("投入")
                            onClicked: {
                                $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套PSS投入\''))
                            }
                        }
                        EXC_Normal_BtnUncheckSecret_highStyle{
                            width: parent.parent.width/7
                            nameText: qsTr("退出")
                            onClicked: {
                                $modbusInterface.sl_modbusWriteImpulse($sqlMcDefine.qml_queryTableOnce('SELECT dec FROM 写命令 WHERE define='+'\'B套PSS退出\''))
                            }
                        }
                    }

                }

            }
        }

        onCurrentIndexChanged: {
            switch(p8_swipeView.currentIndex)
            {
            case 0:
                button.checked = true
                button2.checked = false
                break;
            case 1:
                button.checked = false
                button2.checked = true
                break;
            }
        }
    }

    EXC_Normal_BtnSytle {
        id: button
        nameText: qsTr("运行模式切换")
        width: parent.width*0.27
        height: parent.height*0.09
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.2
        anchors.topMargin: parent.height/20
        anchors.top: p8_swipeView.bottom
        onClicked: {
            if(p8_swipeView.currentIndex==0)
                checked = true;
            else
                p8_swipeView.currentIndex = 0
        }
    }

    EXC_Normal_BtnSytle {
        id: button2
        width: parent.width*0.27
        height: parent.height*0.09
        nameText: qsTr("PSS投退操作")
        anchors.left: parent.left
        anchors.leftMargin: parent.width*0.6
        anchors.topMargin: parent.height/20
        anchors.top: p8_swipeView.bottom
        onClicked: {
            if(p8_swipeView.currentIndex==1)
                checked = true;
            else
                p8_swipeView.currentIndex = 1
        }
    }

}


